home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TSR / PPTSR10 / TPHEX.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-12  |  2KB  |  82 lines

  1. {$f+}
  2. (*
  3. Program  : tphex.pas
  4. Function : unit for displaying all kinds of numeric types in hexadecimal
  5. Author   : P.Peters (pp@win.tue.nl)
  6. Date     : Somewhere 1990-ish
  7. *)
  8.  
  9. Unit TPHex;
  10.  
  11. Interface
  12.  
  13. Function HexL( x : LongInt; l : Byte ) : String;
  14.  
  15. Function HexByte( b : Byte ) : String;
  16.  
  17. Function HexWord( w : Word ) : String;
  18.  
  19. Function HexInteger( i : Integer ) : String;
  20.  
  21. Function HexLongInt( l : LongInt ) : String;
  22.  
  23. Function HexPointer( p : Pointer ) : String;
  24.  
  25. Implementation
  26.  
  27. Const
  28.   HexTable : Array[0..15] Of Char = '0123456789ABCDEF';
  29.  
  30. {
  31. Function HexL( x : LongInt; l : Byte ) : String;
  32. Var s : String;
  33. Begin
  34.   s := '';
  35.   For l := l DownTo 1 Do
  36.     s := s + HexTable[(x shr ((l-1)*4)) And $0f];
  37.   HexL := s;
  38. End;
  39. }
  40.  
  41. Function HexL( x : LongInt; l : Byte ) : String;
  42. Begin
  43.   HexL[0] := Char(l);
  44.   For l := l DownTo 1 Do Begin
  45.     HexL[l] := HexTable[x And $0f];
  46.     x := x shr 4;
  47.   End;
  48. End;
  49.  
  50. Function HexByte( b : Byte ) : String;
  51. Begin
  52.   HexByte := HexL( b, 2);
  53. End;
  54.  
  55. Function HexWord( w : Word ) : String;
  56. Begin
  57.   HexWord := HexL( w, 4 );
  58. End;
  59.  
  60. Function HexInteger( i : Integer ) : String;
  61. Begin
  62.   HexInteger := HexL( i, 4 );
  63. End;
  64.  
  65. Function HexLongInt( l : LongInt ) : String;
  66. Begin
  67.   HexLongInt := HexL( l, 8 );
  68. End;
  69.  
  70. Function HexPointer( p : Pointer ) : String;
  71. Type
  72.   PtWd    = Record
  73.               Case Boolean Of
  74.                 True  : ( Pt  : Pointer );
  75.                 False : ( O,S : Word );
  76.             End;
  77. Begin
  78.   HexPointer := HexL( PtWd(p).S, 4 ) + ':' + HexL( PtWd(p).O, 4);
  79. End;
  80.  
  81. End {TPHex}.
  82.